package service.impl;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import dao.UserDao;
import dao.UserDaoFactory;
import dao.impl.UserDaoImpl;
import entity.User;
import service.UserService;

//@Component("userService")
@Service("userService")
public class UserServiceImpl implements UserService{
	
	public UserServiceImpl() {
		System.out.println("UserServiceImpl()");
	}
	
	//@Autowired
	public UserServiceImpl(UserDao userDao) {
		System.out.println("UserServiceImpl(UserDao userDao)");
		this.userDao=userDao;
	}

	//UserDao userDao = new UserDaoImpl();
//	@Autowired
//	@Qualifier("userDao")
	@Resource(name="userDao")
	private UserDao userDao ;  //  = UserDaoFactory.getInstance(); //UserDao就是UserServiceImpl的依赖
											//UserDao就是UserServiceImpl的属性
	@Override
	public int save(User user) {
		// TODO Auto-generated method stub
		//int a = 1/0;
		return userDao.save(user);
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	

}
